import Cesium, { AssociativeArray } from '../Ces/Cesium'
import WeFontAltas from './WeFontAltas'
import We from '../Core/We'

class WeFontAltasManager {
  WE: We
  _collection: AssociativeArray
  constructor(WE) {
    this.WE = WE
    this._collection = new Cesium.AssociativeArray()
  }

  get(font, url) {
    let fontAtals = this._collection.get(font)

    if (fontAtals instanceof WeFontAltas && fontAtals.ready) {
      return Promise.resolve(fontAtals)
    }

    if (!fontAtals) {
      fontAtals = new WeFontAltas({
        url,
      })
      //@ts-ignore
      fontAtals.ininitAtals(this.WE.viewer.scene.context)
      this._collection.set(font, fontAtals)
    }

    return fontAtals.readyPromise
  }

  destroy() {
    this._collection.values.forEach((element) => {
      element.destroy()
    })

    return Cesium.destroyObject(this)
  }

  isDestroyed() {
    return false
  }

}


export default WeFontAltasManager
